package com.learn.project2.controller.admin;

import com.learn.project2.model.bo.admin.ad.AdCreateBO;
import com.learn.project2.model.bo.admin.ad.AdDeleteBO;
import com.learn.project2.model.bo.admin.ad.AdListBO;
import com.learn.project2.model.bo.admin.ad.AdUpdateBO;
import com.learn.project2.model.vo.admin.ad.AdCreateVO;
import com.learn.project2.model.vo.admin.ad.AdListVO;
import com.learn.project2.model.vo.admin.ad.AdUpdateVO;
import com.learn.project2.service.admin.ad.AdService;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author 岳子昂
 * @date 2022-01-06 22:08
 * @version 1.0
 */
@RequestMapping("admin/ad")
@RestController
public class AdController {
    @Autowired
    AdService adService;

    /**
     * @description: 43
     * @param:
     * @return:
     * @author 岳子昂
     * @date: 2022-01-06 22:09
     */
    @RequestMapping("list")
    @RequiresPermissions(value = {"admin:ad:list"})
    public Result list(AdListBO adListBO){
        AdListVO adListVO = adService.list(adListBO);
        return Result.ok(adListVO);
    }

    /**
     * @description: 44
     * @param:
     * @return:
     * @author 岳子昂
     * @date: 2022-01-06 22:09
     */
    @RequestMapping("create")
    @RequiresPermissions(value = {"admin:ad:create"})
    public Result create(@RequestBody AdCreateBO adCreateBO){
        AdCreateVO adCreateVO = adService.create(adCreateBO);
        // 判断link是否为空
        if (adCreateVO.getLink()==null){
            return Result.fail("活动链接不能为空");
        }
        return Result.ok(adCreateVO);
    }

    /**
     * @description: 45
     * @param:
     * @return:
     * @author 岳子昂
     * @date: 2022-01-06 22:09
     */
    @RequestMapping("update")
    @RequiresPermissions(value = {"admin:ad:update"})
    public Result update(@RequestBody AdUpdateBO adUpdateBO){
        AdUpdateVO adUpdateVO = adService.update(adUpdateBO);
        return Result.ok(adUpdateVO);
    }

    /**
     * @description: 46
     * @param:
     * @return:
     * @author 岳子昂
     * @date: 2022-01-06 22:09
     */
    @RequestMapping("delete")
    @RequiresPermissions(value = {"admin:ad:delete"})
    public Result delete(@RequestBody AdDeleteBO adDeleteBO){
        adService.delete(adDeleteBO);
        return Result.ok();
    }

}
